package cn.daniellee.plugin.pr.command;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.HumanEntity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class RedstoneCompleter implements TabCompleter {

	private final String[] subCommands = {"help", "invite", "accept", "clear", "cancel", "reload"};

	@Override
	public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
		if (strings.length == 0) return Arrays.asList(subCommands);
		else if (strings.length == 1) return Arrays.stream(subCommands).filter(string -> string.startsWith(strings[0])).collect(Collectors.toList());
		else if (strings.length == 2) {
			if ("invite".equalsIgnoreCase(strings[0]) || "accept".equalsIgnoreCase(strings[0]) || "clear".equalsIgnoreCase(strings[0]) || "cancel".equalsIgnoreCase(strings[0])) {
				return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList());
			}
		}
		return new ArrayList<>();
	}

}
